import Vue from 'vue'
import VueRouter from 'vue-router'

import Index from '@/views/index/index.vue'
import Fenlei from '@/views/fenlei/fenlei.vue'
import Shop from '@/views/shop/shop.vue'
import My from '@/views/my/my.vue'
import JianLi from '@/views/jianli/jianli.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    name: 'Index',
    component: Index
  },
  {
    path: '/fenlei',
    name: 'Fenlei',
    component: Fenlei
  },
  {
    path: '/shop',
    name: 'Shop',
    component: Shop
  },
  {
    path: '/my',
    name: 'My',
    component: My,
      //嵌套路由
    children:[
      {
        path:'jianli',
        component:JianLi
      },
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//在路由的原型上加一个路由重复点击时的抛出异常
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router